<?php

class MedLine
{
    var $searchHost = "http://wsearch.nlm.nih.gov/ws/query";
    var $mError = '';

    function _processCurl($url)
    {
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_HEADER, 0);
        //curl_setopt($ch, CURLOPT_PROXY, "http://192.168.4.102:4044");
        //curl_setopt($ch, CURLOPT_PROXYPORT, 4044);
	$data = curl_exec($ch);
        curl_close($ch);
        $results = new SimpleXmlElement($data, LIBXML_NOCDATA);
	return $results;
    }

    public function MediLineSearch($query, $db)
    {
        if('' == $query)
        {
            $this->mError = "Query is blank";
            return false;
	}
        
        $url = $this->searchHost . "?db=" . $db . "&term=" . $query;

        $results = $this->_processCurl($url);

        return $results;
    }

    function GetError()
    {
	return $this->mError;
    }
}
?>
